﻿using EscPrinterVfpV1d0.Entity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;

namespace EscPrinterVfpV1d0
{
    public class Class1:Iclass1
    {
        public string DoNothing()
        {
            return "VfpUsingC#DllSuccessful!!";
        }
        public void Initialize()
        { }
        public void Dispose()
        { }
        /// <summary>
        /// 连接到打印机
        /// </summary>
        /// <param name="ip">ip地址</param>
        /// <param name="port">端口</param>
        /// <returns>是否连接成功</returns>
        public bool ConnectToPrinter(string ip, int port)
        {
            bool result = false;
            try
            {
                TcpClient PrinterTcpClient = null;
                if (PrinterTcpClient == null || (PrinterTcpClient != null && (!PrinterTcpClient.Connected)))
                {
                    //2秒的连接超时
                    PrinterTcpClient = TcpClientWithTimeoutV1d0.TryConnect(ip, port, 2000);
                    if (PrinterTcpClient != null && PrinterTcpClient.Connected)
                    {
                        result = true;
                    }
                    else result = false;
                }
            }
            catch (Exception ex)
            {
                //SimpleLoger.Instance.Error(ex);
                result = false;
            }
            return result;
        }
    }
    public interface Iclass1
    {
        void Initialize();
        void Dispose();
        string DoNothing();
    }
}
